package com.smart.manager.member.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.Page;
import com.smart.manager.member.entities.bodys.RMemberAccount;
import com.smart.manager.member.entities.models.MemberCoinBill;
import com.smart.manager.member.entities.models.MemberProfileAccount;
import com.smart.manager.member.repository.MemberAccountRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author Administrator
 */

@Api(tags = "会员账户")
@RestController
@RequestMapping(SmartConstant.MANAGER_API_PREFIX + "member/profile/account")
@RequiredArgsConstructor
public class ProfileAccountApi {

    private final MemberAccountRepository accountRepository;


    @GetMapping(value = "pageList")
    @ApiOperation(value = "查询账户")
    @SaCheckPermission("member:profile:account:pageList")
    public AjaxResult<Page<MemberProfileAccount>> pageList(@Validated RMemberAccount.SearchBody body) {
        Page<MemberProfileAccount> result = accountRepository.pageList(body);
        return AjaxResult.data(result);
    }




    @PostMapping(value = "billList")
    @ApiOperation(value = "查询账户明细")
    @SaCheckPermission("member:profile:account:billList")
    public AjaxResult<List<MemberCoinBill>> findBillList(@RequestBody @Validated RMemberAccount.FindBillBody body) {
        List<MemberCoinBill> result = accountRepository.findCoinBillList(body);
        return AjaxResult.data(result);
    }

    @PostMapping(value = "changeCoin")
    @ApiOperation(value = "调整账户金币")
    @SaCheckPermission("member:profile:account:changeCoin")
    public AjaxResult<String> changeCoin(@RequestBody @Validated RMemberAccount.ChangeCoinBody body) {
        accountRepository.saveEvent(body.getMemberId(), body.getEvent(), body.getQuantity(), body.getRemark());
        return AjaxResult.success();
    }


}
